/**
    小程序跳转按钮
**/
let wxutil = require("wxUtil");
cc.Class({
    extends: cc.Component,

    properties: {
        iconFrame:[cc.SpriteFrame],
        spIcon:cc.Sprite,
        lbName:cc.Label,
        index:0,
        typeName:'',
        showName:false, 
        hasAnima:false,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.setInfo(this.typeName,this.index);
    },

    start () {
    },
    /**
    *index:图片和名称的下表索引
    *typeName:位置名称，比如"菜单"界面
    **/
    setInfo(typeName,index){
        this.names = ["安仁赛车","数字一块消","吃我一熊屁"];
        this.wxAppids = ["wxc4d4d883155e249b","wx67994a6a5befd765","wxc20b29365d9385d3"];
        this._index = 0;
        this.node.active = !this.hasAnima;
        this._typeName = typeName;
        this._index = index;
        this.lbName.string = this.names[index];
        this.lbName.active = this.showName;
        this.spIcon.spriteFrame = this.iconFrame[index];
        if(this.hasAnima) this.runBtnAnima();
    },
    runBtnAnima: function () {
        this.node.active = true;
        // this.initBtnSp();
        this.node.stopAllActions();
        let action1 = cc.rotateTo(0.2, 10);
        let action2 = cc.rotateTo(0.2, -10);
        let action6 = cc.rotateTo(0.1, 0);
        let delayAction1 = cc.delayTime(0.5);
        let action3 = cc.rotateTo(0.1, 7);
        let action4 = cc.rotateTo(0.1, -7);
        let action7 = cc.rotateTo(0.1, 7);
        let action8 = cc.rotateTo(0.1, -7);
        let action5 = cc.rotateTo(0.1, 0);
        let delayAction2 = cc.delayTime(1);
        this.node.runAction(cc.repeatForever(cc.sequence(action1, action2, action6, delayAction1,
            action3, action4, action7, action8, action5, delayAction2)));
    },

    onClickJump(){
        wxutil.goToOtherProgram(this.wxAppids[this._index], "", function (bvar) {
            let result = bvar ? "成功":"失败";
        }.bind(this), "");
    },

    // update (dt) {},
});
